home *** CD-ROM | disk | FTP | other *** search
- /* LOADER.C -- Download DSP56001 programs to the DSP CARD 3
- *
- * Copyright (C) by Alef Null 1990, 1991
- * Author(s): Jarkko Vuori, OH2LNS
- * Modification(s):
- */
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <memory.h>
- #include "dspio.h"
-
-
- /* extended downloader code */
- static long extloader[] = {
- 0x0003F8, 0x300A1B, 0x61F400, 0x0011E0, 0x061F80, 0x000007, 0x07D884, 0x075984, 0x0AF080, 0x0011E0,
- 0x0AA983, 0x0011EA, 0x0AA980, 0x0011E2, 0x084E2B, 0x300003, 0x0AF0AA, 0x0011FC, 0x0AF080, 0x0011E0, 0x0AA980,
- 0x0011E0, 0x2D0100, 0x2D0205, 0x0AF0AA, 0x0011F9, 0x200005, 0x0AF0AA, 0x0011F6, 0x0858EB, 0x0AF080, 0x0011E0,
- 0x0858AB, 0x0AF080, 0x0011E0, 0x08586B, 0x0AF080, 0x0011E0, 0x0502BA, 0x0000B9, 0x0C0000
- };
-
- static struct {
- char *name;
- unsigned words,
- maxaddress;
- long *data;
- unsigned char *touched;
- } memspaces[3] = {
- { "P", 0, 0x11df, }, // extended loader in 11E0H - 11FFH
- { "X", 0, 0x08ff, },
- { "Y", 0, 0x08ff, }
- };
-
- /*
- * Toggle HF0 flag
- */
- static void ToggleHF0(void) {
- WriteByte(ICR, 0x08); WriteByte(ICR, 0x00);
- }
-
-
- /*
- * Download given datablock
- */
- static void DownloadBlock(long *data, unsigned len) {
- register long *pp;
-
- //WriteByte(ICR, 0x02);
- for (pp = data; pp < data+len; pp++) {
- WriteByte(TXH, (unsigned)(*pp >> 16));
- WriteByte(TXM, (unsigned)(*pp >> 8));
- WriteByte(TXL, (unsigned)*pp);
- }
- }
-
-
- /*
- * Download previously opened file
- */
- void DownLoad(int fMsg) {
- DATASPACE space;
- long word;
- unsigned address;
- int i, fResult, fInternal = -1;
-
- ResetCard();
- for (i = p; i <= y; i++)
- if (!(
- (memspaces[i].data = calloc(memspaces[i].maxaddress+1, sizeof(long))) &&
- (memspaces[i].touched = calloc(memspaces[i].maxaddress+1, sizeof(unsigned char)))
- )) {
- fprintf(stderr, "loader error: not enought memory\n");
- return;
- }
-
- /* read program from file to memspaces */
- while (!(fResult = ReadWord(&space, &address, &word))) {
- if (space != p || address >= 512)
- fInternal = 0;
-
- if (address > memspaces[space].maxaddress) {
- fprintf(stderr, "loader error: too big %s space, allowed range %04XH-%04XH\n", memspaces[space].name, 0, memspaces[space].maxaddress);
- return;
- }
-
- memspaces[space].data[address] = word;
- memspaces[space].words = max(memspaces[space].words, address+1);
- memspaces[space].touched[address] = -1;
- }
- if (fResult < 0)
- return;
-
- /* then send it to the DSP CARD 3 */
- if (fInternal) {
- /* only internal P memory used, use internal 56001 bootloader only */
- DownloadBlock(memspaces[p].data, memspaces[p].words);
- ToggleHF0();
- if (fMsg)
- printf("%u words to P space downloaded\n", memspaces[p].words);
- } else {
- /* external memories (or internal datamemories used), first download the extented loader */
- DownloadBlock(extloader, sizeof(extloader)/sizeof(long));
-
- for (i = p; i <= y; i++)
- if (memspaces[i].words) {
- /* select space */
- ToggleHF0();
- WriteByte(TXH, 0); WriteByte(TXM, 0); WriteByte(TXL, i+1);
-
- /* then download it */
- DownloadBlock(memspaces[i].data, memspaces[i].words);
- }
-
- /* tell to the extended loader to start program */
- ToggleHF0();
- WriteByte(TXH, 0); WriteByte(TXM, 0); WriteByte(TXL, 0);
- if (fMsg)
- printf("%u,%u,%u words to P,X,Y spaces downloaded\n", memspaces[p].words,
- memspaces[x].words,
- memspaces[y].words);
- }
- }
-
-
- /*
- * Read a word from DSP CARD 3
- */
- long ReadHostWord(void) {
- long data;
-
- data = ReadByte(RXH) << 16L;
- data |= (unsigned)ReadByte(RXM) << 8L;
- data |= (unsigned)ReadByte(RXL);
-
- return (data > 8388607L ? data - 16777216L : data);
- }
-
-
- /*
- * Check that the given dump is ok
- */
- void CheckMemDump(void) {
- unsigned address;
- int i;
-
- /* wait preamble */
- printf("Waiting sync pattern...");
- while (!kbhit())
- if ((ReadByte(ISR) & 0x01) && ReadHostWord() == 1313L)
- break;
-
- printf(" found, checking data...\n");
- for (i = p; i <= y; i++) {
- printf("Space %s\n", memspaces[i].name);
-
- for (address = 0; address < memspaces[i].maxaddress; address++) {
- while (!kbhit())
- if (ReadByte(ISR) & 0x01) {
- long data = ReadHostWord();
-
- if (memspaces[i].touched[address] && memspaces[i].data[address] != data)
- printf("\t%s %04X %06lX (must have been %06lX)\n", memspaces[i].name, address, data, memspaces[i].data[address]);
-
- break;
- }
- }
- }
- }
-